﻿
@model EstimateShippingModel
@using Nop.Web.Models.ShoppingCart;
@if (Model.Enabled)
{
    <div class="col-md-6 offer offer-default">
        <div class="shipping">
            <script type="text/javascript">
                $(function () {
                    $("#@Html.FieldIdFor(model => model.CountryId)").change(function () {
                        var selectedItem = $(this).val();
                        var ddlStates = $("#@Html.FieldIdFor(model => model.StateProvinceId)");
                        var estimateProgress = $("#estimate-shipping-loading-progress");
                        estimateProgress.show();
                        $.ajax({
                            cache: false,
                            type: "GET",
                            url: "@(Url.RouteUrl("GetStatesByCountryId"))",
                            data: { "countryId": selectedItem, "addEmptyStateIfRequired": "true" },
                            success: function (data) {
                                ddlStates.html('');
                                $.each(data, function (id, option) {
                                    ddlStates.append($('<option></option>').val(option.id).html(option.name));
                                });
                                estimateProgress.hide();
                            },
                            error: function (xhr, ajaxOptions, thrownError) {
                                alert('Failed to retrieve states.');
                                estimateProgress.hide();
                            }
                        });
                    });
                });
            </script>
            <div class="estimate-shipping">
                <div class="title">
                    <strong>@T("ShoppingCart.EstimateShipping")</strong>
                </div>
                <div class="hint">@T("ShoppingCart.EstimateShipping.Tooltip")</div>
                <div class="shipping-options">
                    <div class="inputs">
                        @Html.LabelFor(model => model.CountryId, new { }, ":")
                        <span class="required">*</span>
                        @Html.DropDownListFor(model => model.CountryId, Model.AvailableCountries, new { @class = "form-control square-box" })

                    </div>
                    <div class="inputs">
                        @Html.LabelFor(model => model.StateProvinceId, new { }, ":")
                        @Html.DropDownListFor(model => model.StateProvinceId, Model.AvailableStates, new { @class = "form-control square-box" })
                        <span id="estimate-shipping-loading-progress" style="display: none;" class="please-wait">@T("Common.Wait...")</span>
                    </div>
                    <div class="inputs">
                        @Html.LabelFor(model => model.ZipPostalCode, new { }, ":")
                        @Html.TextBoxFor(model => model.ZipPostalCode, new { @class = "form-control square-box" })
                    </div><br />
                    <div class="inputs">
                        <input type="submit" name="estimateshipping" value="@T("ShoppingCart.EstimateShipping.Button")" class="btn btn-default" />
                    </div>
                </div><br />
                @if (Model.ShippingOptions.Count > 0)
                {
                    <div class="alert alert-info square-box">
                        @foreach (var shippingOption in Model.ShippingOptions)
                        {
                            <div class="shipping-option-item">
                                <strong class="option-name">
                                    @T("ShoppingCart.EstimateShipping.ShippingOptionWithRate", shippingOption.Name, shippingOption.Price)
                                </strong>
                                <span class="option-description">
                                    @Html.Raw(shippingOption.Description)
                                </span>
                            </div>
                        }
                    </div>
                }
                @if (Model.Warnings.Count > 0)
                {
                    <div class="alert alert-danger square-box">

                        @foreach (var error in Model.Warnings)
                        {
                            <div>@error</div>
                        }

                    </div>
                }
            </div>
        </div>
    </div>
}